package com.mqy.spring.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 13159 //作者
 * @version V1.0 //版本
 * @Project 2022.3.8springMVCjson
 * @Package com.mqy.spring.controller
 * @Description:
 * @Date 2022/3/8 11:06//日期
 * @Motto:放下杂念,只为迎接明天更好的自己
 */
@Controller
@SessionAttributes({"name","diyige","age"})
public class TestController {
    @RequestMapping("/testrequest")
    public String test1(String name, HttpServletRequest request) {
        request.setAttribute("diyige", name);
        return "/wang.jsp";
    }

    @RequestMapping("/testmodel")
    public String test2(String name, Model model) {
        model.addAttribute("diyige", name);
        return "/wang.jsp";
    }

    @RequestMapping("/testModelAndView")
    public ModelAndView test3(String name, ModelAndView modelAndView) {
        modelAndView.addObject("diyige",name);
        modelAndView.setViewName("/wang.jsp");
        return modelAndView;
    }

    @RequestMapping("/testSessionAttributes")
    public ModelAndView test4(String name, ModelAndView modelAndView) {
        modelAndView.addObject("diyige", name);
        modelAndView.setViewName("/wang.jsp");
        return modelAndView;
    }
}
